package com.gsc.controller;

import com.gsc.domain.ResponseResult;
import com.gsc.domain.entity.Category;
import com.gsc.domain.entity.Link;
import com.gsc.domain.vo.PageVo;
import com.gsc.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.crypto.interfaces.PBEKey;

/**
 * @author gscstart
 * @create 2023/2/24-13:56
 */
@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @GetMapping("/list")
    public ResponseResult selectPageLink(Integer pageNum, Integer pageSize, Link link){
        PageVo pageVo = linkService.selectPageLink(pageNum,pageSize,link);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    public ResponseResult addLink(@RequestBody Link link){
        linkService.save(link);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult selectLinkById(@PathVariable("id") Long id){
        Link link = linkService.getById(id);
        return ResponseResult.okResult(link);
    }
    @PutMapping
    public ResponseResult putLink(@RequestBody Link link ){
        linkService.updateById(link);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteLink(@PathVariable("id") Long id){
        linkService.removeById(id);
        return ResponseResult.okResult();
    }

}
